package com.spark.colliery.module.mine.fragment

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.spark.colliery.R
import com.spark.common.BaseFragment
import com.spark.data.model.TrackHistoryModel
import kotlinx.android.synthetic.main.frag_track_history.*

/**
 * 资料追踪历史
 */
class TrackHistoryFragment : BaseFragment() {
    companion object {
        fun newInstance(): TrackHistoryFragment {
            val fragment = TrackHistoryFragment()
            val args = Bundle()

            fragment.arguments = args
            return fragment
        }
    }

    private var curPage = 1
    private lateinit var trackHistoryAdapter: TrackHistoryAdapter

    override fun contentResId(): Int {
        return R.layout.frag_track_history
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        iv_back.setOnClickListener { pop() }
        iv_category.setOnClickListener { }

        trackHistoryAdapter = TrackHistoryAdapter(R.layout.item_track_history)
        recy_track_history.adapter = trackHistoryAdapter
        recy_track_history.layoutManager = LinearLayoutManager(context)

        trackHistoryAdapter.addData(TrackHistoryModel(
                id = "1",
                title = "文件传输",
                state = "成功",
                time = "1秒前",
                content = "这可是善本，注意保管"
        ))

        refresh_layout.setOnRefreshListener { }
        refresh_layout.setOnLoadmoreListener { }
    }
}

class TrackHistoryAdapter(layoutRes: Int) : BaseQuickAdapter<TrackHistoryModel, BaseViewHolder>(layoutRes) {
    override fun convert(helper: BaseViewHolder?, item: TrackHistoryModel?) {
        if (item == null) return
        helper?.apply {
            setText(R.id.tv_title, item.title)
            setText(R.id.tv_state, item.state)
            setText(R.id.tv_content, item.content)
            setText(R.id.tv_time, item.time)
        }
    }

}